<!DOCTYPE html>
<!--[if IE 8]>			<html class="ie ie8"> <![endif]-->
<!--[if IE 9]>			<html class="ie ie9"> <![endif]-->
<!--[if gt IE 9]><!-->	<html> <!--<![endif]--><head>
<meta charset="utf-8">
<title>{$menu.menu_seo_title|default=$site_seo_title} {$site_name}</title>
<meta name="keywords" content="{$menu.menu_seo_key|default=$site_seo_keywords}" />
<meta name="description" content="{$menu.menu_seo_des|default=$site_seo_description}">
{include file="public:head" /}

</head>
<body class="page">
<div class="wrap">
    {include file="public:nav" /}
    <div id="main-cmf">
    <form action="{:url("home/order/confirmorder")}" method="post">
        <div class="breadcrumb-wrapper">
        
            <div class="container">
                <div class="row page-title">
                    <div class="col-lg-12 col-md-12 col-xs-12 col-sm-6 address">
                        <h4 class="clearfix">
                        	确认收货地址
                        	<a href="{:url('home/center/address')}" class="pull-right addressmenage">管理收货地址</a>
                        </h4>
                        <ul>
                        {foreach name="address" item="a"}
                        	<li id="address_{$a["id"]}" {if condition="$a['is_default'] eq 1"}class="select"><div class="marker"><i class="fa fa-map-marker"></i> 寄送至</div>{else/}><div class="marker"></div>{/if} 
                                <input type="radio" name="address_id" value="{$a["id"]}" {if condition="$a['is_default'] eq 1"} checked{/if} onClick="checkaddress(this)"> 
                                <strong>{$a["address"]}</strong> ({$a["man"]} 收) {$a["mobile"]} &nbsp; &nbsp; &nbsp;
                                {if condition="$a['is_default'] eq 1"}默认地址{/if}
                            </li>
                        {/foreach}
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        
        
        
        <div class="content">
            <div class="container">
                <div class="row orderinfo">
                    <h4>
                        确认订单信息
                    </h4>
                    <table class="table">
                    	<thead>
						<tr>
                        	<th width="30%">商品</th>
                            <th width="15%">属性</th>
                            <th width="10%">单价</th>
                            <th width="15%">数量</th>
                            <th width="20%">优惠</th>
                            <th>小计</th>
                        </tr>
                        </thead>
                        <tbody>
                        {foreach name="goods" item="g"}
                        <tr id="goods_item_{$g["id"]}">
                        	<td>
                            {notempty name="g['thumb']"}
                            <a class="good_img" href="#"><img src="{$g["thumb"]}"></a>
                            {/notempty}
                            <a class="good_title" href="#">{$g["goods_title"]}</a>
                            <input type="hidden" name="id[]" value="{$g["id"]}">
                            </td>
                            <td>分类：{$g["cate_name"]}</td>
                            <td>{$g["price"]}</td>
                            <td>
                            <a href="javascript:void(0);" class="fa fa-plus-square plus_btn" rel="{$g["id"]}"></a>&nbsp;
                            <input type="text" name="number[]" class="goodnumber" value="{$g["number"]}" onKeyUp="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" maxlength="4">&nbsp;
                            <a href="javascript:void(0);" class="fa fa-minus-square minus_btn" rel="{$g["id"]}"></a>
                            </td>
                            <td class="tyouhui">{$g.youhui}</td>
                            <td class="tprice">￥<span>{$g["totalprice"]}</span></td>
                        </tr>
                        {/foreach}
                        </tbody>
					</table>
                    
                    
                    
                    <table class="table" style="background-color:#f8f8f8">
                    	<tbody>
                        	<tr>
                            	<td rowspan="2">备注：<textarea name="remark"  style="width:90%" rows="4" ></textarea></td>
                                <td width="40%" style="position:relative">优惠：<select name="youhui"><option value="">无</option></select> <span class="more"></span></td>
                            </tr>
                            <tr>
                            	<td style="position:relative">快递：普通快递 <span class="more"></span></td>
                            </tr>
                            <tr>
                            	<td align="right" colspan="2" id="total">总计：<span>￥{$total}</span></td>
                            </tr>
                        </tbody>
                    </table>
                    
                    <h4>
                        选择支付方式 {if condition="$user_money gt 0"}<em style="font-weight:normal; font-size:12px; margin-left:20px; font-style:normal">当前余额:{$user_money}</em>{/if}
                    </h4>
                    <style type="text/css">
                       .pay-list{}
					   .pay-list a{ border:2px solid #dedede; margin:0 10px 5px 0; display:inline-block; position:relative}
					   .pay-list a i{ position:absolute; right:0; bottom:0}
					   .pay-list a.curr{border:2px solid #F00;}
					   .pay-list a.curr i{width:50px; height:50px; display:block;background:url('{$yf_theme_path}public/payment/images/sys_item_selected.gif') no-repeat}
                    </style>
                    
                    
                     <div class="form-group pay-list">  
                     
                     <a id="a_alipay" href="javascript:;"   {if condition="$user_money lt $total"}class="curr"{/if} data='alipay'>
                        <img  src="{$yf_theme_path}public/payment/images/alipay.png"/> <i></i>
                     </a>
                     
                     <a id="a_wxpayqrcode" href="javascript:;" data='wxpayqrcode'>
                       <img  src="{$yf_theme_path}public/payment/images/wechatpay.png"/> <i></i>
                     </a>
                     
                     <a id="a_money" href="javascript:;" data='money' {if condition="$user_money lt $total"}style="display:none"{else/}class="curr"{/if}>
                       <img  src="{$yf_theme_path}public/payment/images/yue.png"/> <i></i>
                     </a>

                     </div>                        
                   
                     
                    
                    
                    <div style="text-align:right">
                    <input type="hidden" id="user_money" name="user_money" value="{$user_money}"> 
                    <input type="hidden" id="pay_type" name="pay_type" value="{if condition="$user_money lt $total"}alipay{else/}money{/if}">
                    <button type="submit" class="btn btn-danger btn-lg"> 确认订单 </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </form>
    {include file="public:footer"/}
</div>
{include file="public:scripts"/}
<script>
var total = {$total};
var time  = 0;

function checkaddress(o){
	var id = o.value;
	$("li.select .marker").html("");
	$("li.select").removeClass("select");
	$("#address_"+id+' .marker').html('<i class="fa fa-map-marker"></i> 寄送至');
	$("#address_"+id).addClass("select");
}

function getprice(id,number){
	var now = parseInt(new Date().getTime());
	
	if(now-time < 500)
		return false;

	var tpo     = $("#goods_item_"+id+" .tprice span");
	var tyouhui = $("#goods_item_"+id+" .tyouhui");
	var index = layer.load(1);
	$.post("{:url("home/order/getprice")}",{id:id,number:number},function(res){		
		layer.close(index);																  
		if(res.err == 0){
			total = (total-parseInt(tpo.text())+res.data.totalprice);
			tpo.text(res.data.totalprice);
			tyouhui.html(res.data.youhui);
			if($("#user_money").val()  >= res.data.totalprice){
				 $("#a_money").show();
				 $("#pay_type").val('money');
				 $(".pay-list a").removeClass('curr');
				 $("#a_money").addClass('curr');
			}else{
			     $("#a_money").hide();
				 $("#pay_type").val('alipay');
				 $(".pay-list a").removeClass('curr');
				 $("#a_alipay").addClass('curr');
			}
			$("#total").html('总计：<span>￥'+total+'</span>');
		}else{
			layer.alert(res.msg);	
		}
	});
}

$(function(){
	$(".plus_btn").click(function(){
		var o = $(this).next();						  
		var number = o.val();							  
		if(isNaN(number)){
			o.val(1);		
		}else{
			if(number.length<4){
				number++;
				o.val(number);
				time = parseInt(new Date().getTime());
				setTimeout("getprice("+$(this).attr("rel")+","+number+")",600);
			}
		}
	});		
	
	$(".minus_btn").click(function(){
		var o = $(this).prev();						   
		var number = o.val();							  
		if(isNaN(number)){
			o.val(1);		
		}else{
			if(number>1){
				number--;
				o.val(number);
				time = parseInt(new Date().getTime());
				setTimeout("getprice("+$(this).attr("rel")+","+number+")",600);
			}
		}
	});
	
	 $(".pay-list a").click(function(){
							 $(".pay-list a").removeClass('curr');
							 $(this).addClass('curr');
							 $("#pay_type").val($(this).attr('data'));
						  });
})
</script>
</body>
</html>